 // 获取年的所有周数据
import dayjs from 'dayjs'
 function getweek(y) {
  var n = false
  var e_t = 0
  if (y === new Date().getFullYear().toString()) {
    e_t = new Date().getTime()
    n = true
  }
  else {
    var e_t1 = (parseInt(y) + 1).toString()
    e_t = new Date(e_t1).getTime()
  }
  var s_t = new Date(y).getTime()
  var d = 24 * 60 * 60 * 1000
  var s_one = 0
  for (let i = 0; i < 7 ;i++) {
    if (new Date(s_t + (i * d)).getDay() == 1) {
      s_one = new Date(s_t + (i * d)).getTime()
    }
  }
  var s = Math.ceil((e_t - s_one) / d / 7)
  var time_arr = []
  for (let i = 0; i < s ;i++) {
    var a = new Date(s_one + (i * 7) * d)
    var a_t = a.getFullYear() + '-' + ((a.getMonth() + 1) < 10 ? '0' + (a.getMonth() + 1) : (a.getMonth() + 1)) + "-" + (a.getDate() < 10 ? '0' + a.getDate() : a.getDate())
    var b = new Date(s_one + (i * 7) * d + d * 6)
    var b_t = b.getFullYear() + '-' + ((b.getMonth() + 1) < 10 ? '0' + (b.getMonth() + 1) : (b.getMonth() + 1)) + "-" + (b.getDate() < 10 ? '0' + b.getDate() : b.getDate())
    time_arr.push({
      'zhou': `第${(i + 1) < 10 ? '0' + (i + 1) : (i + 1)}周`,
      's': `${a_t}`,
      'e': `${b_t}`,
      'n': `${i === s - 1 && n ? '本周' : ''}`,
      'id': (i + 1),
      'name': `${a_t} ~ ${b_t} ${i === s - 1 && n ? '' : `( 第${(i + 1) < 10 ? '0' + (i + 1) : (i + 1)}周 )`}   ${i === s - 1 && n ? '( 本周 )' : ''}`
    })
  }
  return time_arr
}

export default getweek